﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;

namespace System.Web.Mvc.Html
{
    public static class FormExtensions2
    {
        public static MvcForm BeginForm<TController>(this HtmlHelper htmlHelper,
            Expression<Action<TController>> action) where TController : Controller
        {
            string controllerName = MvcHelper.GetControllerName<TController>();
            MethodCallExpression call = action.Body as MethodCallExpression;
            string actionName = call.Method.Name;
            return htmlHelper.BeginForm(actionName, controllerName);
        }
        public static MvcForm BeginForm<TController>(this HtmlHelper htmlHelper,
            Expression<Action<TController>> action, FormMethod method) where TController : Controller
        {
            string controllerName = MvcHelper.GetControllerName<TController>();
            MethodCallExpression call = action.Body as MethodCallExpression;
            string actionName = call.Method.Name;
            return htmlHelper.BeginForm(actionName, controllerName, method);
        }
        public static MvcForm BeginForm<TController>(this HtmlHelper htmlHelper,
            Expression<Action<TController>> action, FormMethod method, IDictionary<string, object> htmlAttributes) where TController : Controller
        {
            string controllerName = MvcHelper.GetControllerName<TController>();
            MethodCallExpression call = action.Body as MethodCallExpression;
            string actionName = call.Method.Name;
            return htmlHelper.BeginForm(actionName, controllerName, method, htmlAttributes);
        }
        public static MvcForm BeginForm<TController>(this HtmlHelper htmlHelper,
            Expression<Action<TController>> action, FormMethod method, object htmlAttributes) where TController : Controller
        {
            string controllerName = MvcHelper.GetControllerName<TController>();
            MethodCallExpression call = action.Body as MethodCallExpression;
            string actionName = call.Method.Name;
            return htmlHelper.BeginForm(actionName, controllerName, method, htmlAttributes);
        }
    }
}